package com.example.rule.common.enums;

import com.example.rule.common.exception.ClientException;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

@Getter
public enum OperatorEnum {

    EQUAL("等于", "=="),
    NOT_EQUAL("不等于", "!="),
    GREATER_THAN("大于", ">"),
    LESS_THAN("小于", "<"),
    GREATER_OR_EQUAL("大于等于", ">="),
    LESS_OR_EQUAL("小于等于", "<="),
    CONTAIN("包含", "contains"),
    NOT_CONTAIN("不包含", "!contains");

    private final String description;
    private final String symbol;

    OperatorEnum(String description, String symbol) {
        this.description = description;
        this.symbol = symbol;
    }

    private static final Map<String, String> OPERATOR_MAP = new HashMap<>();

    static {
        for (OperatorEnum op : values()) {
            OPERATOR_MAP.put(op.description, op.symbol);
        }
    }


    /**
     * 根据中文描述获取对应的操作符符号
     */
    public static String getSymbolByDescription(String description) {
        String symbol = OPERATOR_MAP.get(description);
        if (symbol == null) {
            throw new ClientException("不支持的操作符: " + description);
        }
        return symbol;
    }
}

